/**
 * @FileName Client.java
 * @Package com.designMode.composite
 * -------------------------------------
 * @function Please write description of function
 * @Date 2016-1-18 下午5:16:22
 * -------------------------------------
 * Copyright (c) 2016,顾博君 All Rights Reserved.
 */
package com.designMode.composite;

/**
 * @author 顾博君
 * @ClassName Client
 * @Date 2016-1-18 下午5:16:22
 * @Function 场景类
 */
public class Client {
    public static void main(String[] args) {
        // 创建一个根节点
        Composite root = new Composite();
        root.operation();
        /*
                  root
                  /  \
             branch   leaf3
             /   \
          leaf1   leaf2
         */
        Composite branch = new Composite();
        branch.add(new Leaf("leaf1"));
        branch.add(new Leaf("leaf2"));

        root.add(branch);
        root.add(new Leaf("leaf3"));

        display(root);
    }

    public static void display(Composite root) {
        for (Component c : root.getChild()) {
            if (c instanceof Leaf) {
                c.operation();
            } else {
                display((Composite) c);
            }
        }
    }
}
